{
open Grammar
open Glob

let in_for=ref false 
}

let newline = '\n' | '\r' '\n'
let letter= ['a'-'z' 'A'-'Z']
let digit = ['0'-'9']
let nombre= '-'? digit+

rule token = parse
  | newline        
      { Lexing.new_line lexbuf; token lexbuf }
  | [' ' '\t'] +  
      { token lexbuf }
  | "add"         
      {  ADD  }
  | "sub"    
      { SUB  }
  | "mul"    
      { MUL  }
  | "quo"  
      { QUO  }
  | "rem"      
      { REM  }
  | "addi" 
      { ADDI }
  | "lw"      
      { LW   }
  | "sw"      
      { SW   }
  | "and"    
      { AND  }
  | "andi"  
      { ANDI }
  | "or"    
      { OR   }
  | "ori" 
      { ORI  }
  | "xor"   
      { XOR  }
  | "nor" 
      { NOR  }
  | "sll"
      { SLL  }
  | "slr"  
      { SLR  }
  | "sar" 
      { SAR  }
  | "beq"  
      { BEQ  }
  | "jal" 
      { JAL  }
  | "jr"  
      { JR   }
  | "j"  
      { J    }
  | letter+ as id    
      { 
	if not(Hashtbl.mem labels id) then begin
	  incr nbLabel;
	  Hashtbl.add labels id (!nbLabel);
	  
	end;
	LABEL (Hashtbl.find labels id)
      }
  | (letter+ as id) (':')
      { 
	if not(Hashtbl.mem labels id) then begin
	  incr nbLabel;
	  Hashtbl.add labels id (!nbLabel);
	  
	end;
	(
	  
	  Hashtbl.add labelsToInstr (Hashtbl.find labels id) (!nbInstr+1);
	);
	token lexbuf
      }
  | nombre as a      { ENTIER (int_of_string a)}
  | "//"             { comment lexbuf }
  | eof              { EOF }

and comment = parse
  | newline {token lexbuf}
  | _       {comment lexbuf}
  | eof     { EOF }
